package com.onetech.adrewards.free.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.onetech.adrewards.free.R;
import com.onetech.adrewards.free.activities.BaseNewActivity;
import com.todddavies.components.progressbar.ProgressWheel;

public class BaseFragment extends Fragment implements
		OnClickListener, OnPageChangeListener{	
	protected View mView = null;
	protected View mNotFoundData = null;
	protected View mWaitingForLoading = null;
	protected View mBtnRetry = null;
	protected ProgressWheel mProgress = null;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return container;
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
		
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
		
	}

	@Override
	public void onPageSelected(int arg0) {
		
	}

	@Override
	public void onClick(View v) {
		
	}
	protected BaseNewActivity getBaseNewActivity(){
		return (BaseNewActivity)getActivity();
	}
	protected void initNotFoundAndLoadingView() {
		mNotFoundData = (LinearLayout) mView
				.findViewById(R.id.notFoundDataContainer);
		mWaitingForLoading = (LinearLayout) mView
				.findViewById(R.id.waitingLoading);
		mProgress = (ProgressWheel) mView.findViewById(R.id.progressWheel);
		mProgress.spin();
		showNotFoundOrLoadingView(false, true);
		mBtnRetry = (LinearLayout) mView.findViewById(R.id.btnRetry);
	}

	protected void initRetryButtonListener() {
		mBtnRetry.setOnClickListener(this);
	}

	protected void showNotFoundOrLoadingView(boolean isShowNotFound,
			boolean isShowLoading) {
		if (isShowNotFound) {
			mNotFoundData.setVisibility(View.VISIBLE);
		} else {
			mNotFoundData.setVisibility(View.GONE);
		}
		if (isShowLoading) {
			mWaitingForLoading.setVisibility(View.VISIBLE);
			mProgress.spin();
		} else {
			mWaitingForLoading.setVisibility(View.GONE);
			mProgress.stopSpinning();
		}
	}
}
